package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 目标:
 *
 * @author YUE
 * @date 2024/6/12 9:29
 */
@Mapper
public interface SetmealMapper {

    @Select("select count(id) from setmeal where category_id = #{id}")
    Integer countByCategoryId(Long id);

    // 新增套餐
    @Insert("insert into setmeal(category_id, name, price, description, image, create_time, update_time, create_user, update_user,status) VALUES" +
            " (#{categoryId},#{name},#{price},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})")
    @AutoFill(type = OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void saveId(Setmeal setmeal);

    /*
      分页查询
     */
    Page<SetmealVO> page(SetmealPageQueryDTO setmealPageQueryDTO);

    /*
      根据id查询套餐数据
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal getById(Long id);

    /*
        删除套餐表
     */
    @Delete("delete from setmeal where id = #{id} ")
    void deleteSetmeal(Long id);

    /*
      修改套餐数据
     */
    @AutoFill(type = OperationType.UPDATE)
    void update(Setmeal setmeal);

    // 根据分类id查询套餐
    List<Setmeal> list(Setmeal setmeal);

    //根据套餐id 查询包含的菜品
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getIdByDish(Long id);
}
